import React, {useEffect,useRef,useState} from 'react'
import {Card} from 'antd'
import {GridContent} from '@ant-design/pro-layout';
import ProTable from '@ant-design/pro-table'
import moment from 'moment';
import {getUserBankCardInfo, getCredentialList,getContractModelList,queryCertificatePage} from '../service';
import { BPMStatusEnum } from '@/utils/constant'

const Certificate = ({oid}) => {
  const actionRef = useRef();
  const [contractList,setContractList] = useState([]);
  const bankColumns = [
    {
      title: '序号',
      render:(text,record,index)=>`${index+1}`,
      hideInSearch: true,
    },
    {
      title: '持卡人姓名',
      dataIndex: 'name',
      hideInSearch: true,
    },
    {
      title: '开户银行',
      hideInSearch: true,
      dataIndex: 'bankAccount',
      key:'bankAccount',
    },
    {
      title: '所属支行',
      hideInSearch: true,
      dataIndex: 'subBranch',
      key:'subBranch',
    },
    {
      title: '银行卡号',
      hideInSearch: true,
      dataIndex: 'bankcardNum',
      key:'bankcardNum',
    },
    {
      title: '生效时间',
      dataIndex: 'effectiveDate',
      hideInSearch: true,
      render: (text) => {
        return text !== '-' ? moment(text).format('YYYY-MM-DD') : '';
      },
    }
  ];
  const qualificationColumns = [
    {
      title: '序号',
      render: (text, record, index) => `${index + 1}`,
      hideInSearch: true,
    },
    {
      title: '姓名',
      dataIndex: 'name',
    },
    {
      title: '证书编号',
      hideInSearch: true,
      dataIndex: 'credentialNo',
    },
    {
      title: '职称系列',
      hideInSearch: true,
      dataIndex: 'jobSeries',
    },
    {
      title: '证书级别',
      hideInSearch: true,
      dataIndex: 'credentialLevel',
    },
    {
      title: '资格名称',
      hideInSearch: true,
      dataIndex: 'credentialName',
    },
    {
      title: '授予时间',
      dataIndex: 'startTime',
      hideInSearch: true,
      render: (text) => {
        return text !== '-' ? moment(text).format('YYYY-MM-DD') : '';
      },
    },
    {
      title: '挂靠状态',
      hideInSearch: true,
      dataIndex: 'hangStatus',
      valueEnum: {
        0: {text: '未审核', status: 'Default'},
        1: {text: '审核中', status: 'Processing'},
        2: {text: '已挂靠', status: 'Success'},
        4: {text: '解除中', status: 'Processing'},
        5: {text: '已解除', status: 'Error'},
      },
    },
    {
      title: '状态',
      dataIndex: 'status',
      hideInSearch: true,
      valueEnum: {
        0: {text: '未审核', status: 'Default'},
        1: {text: '已审核', status: 'Success'},
        2: {text: '拒绝', status: 'Warning'},
      },
    }
  ];
  const proveColumns = [
    {
      title: '序号',
      render:(text,record,index)=>`${index+1}`,
      hideInSearch: true,
    },
    {
      title: '工号',
      dataIndex: 'code'
    },
    {
      title: '姓名',
      dataIndex: 'name'
    },
    {
      title: '公司',
      dataIndex: 'orgName',
    },
    {
      title: '部门',
      dataIndex: 'unitName',
    },
    {
      title: '岗位',
      dataIndex: 'jobName',
    },
    {
      title: '申请时间',
      dataIndex: 'createTime',
      hideInSearch: true,
      render: (text) => {
        return text !== '-' ? moment(text).format('YYYY-MM-DD') : ''
      },
    },
    {
      title: '证明类型',
      dataIndex: 'modelId',
      render: (text) => {
        return  contractList.find((item) => item.id === text)?.name;
      },
    },
    {
      title: '审批状态',
      dataIndex: 'status',
      valueEnum: BPMStatusEnum
    }
  ];

  useEffect(() => {
    getContractModelList().then(res => {
      setContractList(res);
    });
  }, []);

  return (
    <>
      <GridContent>
        <Card title="银行卡" style={{marginBottom: 24}} bordered={false}>
          <ProTable
            actionRef={actionRef}
            rowKey="id"
            request={() => getUserBankCardInfo(oid)}
            columns={bankColumns}
            search={false}
            options={false}
            toolBarRender={false}
          />
        </Card>
        <Card title="资质信息" style={{marginBottom: 24}} bordered={false}>
          <ProTable
            actionRef={actionRef}
            rowKey="id"
            request={(params) => getCredentialList(params, oid)}
            columns={qualificationColumns}
            search={false}
            options={false}
            toolBarRender={false}
          />
        </Card>
        <Card title="证明信息" style={{marginBottom: 24}} bordered={false}>
          <ProTable
            actionRef={actionRef}
            rowKey="id"
            request={(params) => queryCertificatePage(params, oid)}
            columns={proveColumns}
            search={false}
            options={false}
            toolBarRender={false}
          />
        </Card>
      </GridContent>
    </>
  );
};
export default Certificate;
